home *** CD-ROM | disk | FTP | other *** search
Korn shell script | 1995-03-24 | 1.1 KB | 36 lines |
- #! /bin/ksh
- USAGE='USAGE: replace_link FILE_PATH DEST_PATH
- FILE_PATH should be a link whose ultimate desitnation is DEST_PATH.
- Replace FILE_PATH with a link to DEST_PATH.
- '
- # (C) Copyright 1995 by Michael Coulter. All rights reserved.
-
- # Process parameters
- if [ $# -ne 2 ]
- then
- echo "$USAGE" >&2
- echo "Expected 2 arguments, got $#" >&2
- exit 1
- fi
- FILE_PATH="$1"; shift
- DEST_PATH="$1"; shift
- ##echo "replace_link: At 1, DEST_PATH is $DEST_PATH"
- if [ ! -L "$FILE_PATH" ]
- then
- echo "$USAGE" >&2
- echo "FILE_PATH, $FILE_PATH , is not a link." >&2
- exit 1
- fi
- ##echo "replace_link: At 1, DEST_PATH is $DEST_PATH"
- ##echo "replace_link: At 1, FILE_PATH is $FILE_PATH"
- ##echo "replace_link: At 2, DEST_PATH is $DEST_PATH"
- # If DEST_PATH starts with the directory of $FILE, then use a
- # relative link
- FRONT="$(dirname "$FILE_PATH")/"
- eval "DEST_PATH=\"${DEST_PATH#${FRONT}}\""
- ##echo "replace_link: At 3, DEST_PATH is $DEST_PATH"
- echo "replace_link: Replace $FILE_PATH with $DEST_PATH"
- rm "$FILE_PATH"
- ln -s "$DEST_PATH" "$FILE_PATH"
- exit 0
-